// pages/help/help.js
const app = getApp()
const util = require('../../utils/util.js')
Page({
        /**
         * 页面的初始数据
         */
        data: {
                num:0,
                title: "常见问题",//当前页面的标题
                list:''
        },
        /**
         * 生命周期函数--监听页面加载
         */
        onLoad: function(options) {
                this.setData({
                        userName: wx.getStorageSync("userInfo").userName,
                        userUrl: wx.getStorageSync("userInfo").userImgUrl,
                        headerheight: app.globalData.navHeight
                })
                this.request()
        },
        login: function () {
                var that = this
                wx.login({
                        success: function (res) {
                                var code = res.code
                                var data = {
                                        userCode: code,
                                        userImageUrl: "",
                                        userName: ""
                                }
                                util.promotion(app.globalData.user, "POST", data, that.succeed)
                        }
                })
        },
        succeed: function (res) {
                wx.setStorageSync('tekon', res.data.token)
                wx.setStorageSync('userInfo', res.data.user)
                this.request()
        },
        request:function(){
                wx.showNavigationBarLoading()
                wx.showLoading({
                        title: '玩命加载中...',
                })
                var header = {
                        'authorization': wx.getStorageSync("tekon"),
                        'content-type': "application/x-www-form-urlencoded"
                }
                        util.formhttp(app.globalData.appurl +'/common/commonproblem', 'get', '', header, this.stat);
        },
        stat: function(res) {
                var that=this
                if (res.status == 401) {
                        this.login()
                }
                // console.log(res)
                wx.hideNavigationBarLoading()
                wx.hideLoading()
                // console.log(res.data.list)
                var bux = res.data.list
                bux.forEach(function (item, index, array) {
                        array[index] = {
                                title: item.title,
                                content:item.content,
                                status:false
                        }
                        that.setData({
                                list: bux
                        })
                })
        },

        // 展开
        zhankai:function(e){
             let it = this.data.list[e.currentTarget.dataset.num-1]
            it.status = !it.status
            let newList=[];
            newList= this.data.list;
                newList[e.currentTarget.dataset.num - 1] = it
            this.setData({
                    list: newList
            })

        },
        /**
         * 生命周期函数--监听页面初次渲染完成
         */
        onReady: function() {

        },

        /**
         * 生命周期函数--监听页面显示
         */
        onShow: function() {

        },

        /**
         * 生命周期函数--监听页面隐藏
         */
        onHide: function() {

        },

        /**
         * 生命周期函数--监听页面卸载
         */
        onUnload: function() {

        },

        /**
         * 页面相关事件处理函数--监听用户下拉动作
         */
        onPullDownRefresh: function() {

        },

        /**
         * 页面上拉触底事件的处理函数
         */
        onReachBottom: function() {

        },

        /**
         * 用户点击右上角分享
         */
        onShareAppMessage: function() {

        }
})